home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 10-InfoSystems / netscape_info / security-i.frm.z / security-i.frm
Encoding:
Text File  |  2002-06-12  |  16.0 KB  |  538 lines

  1. #!/usr/bin/perl5
  2. #
  3. # security-i.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: security-i.frm,v 1.10 1998/06/16 20:21:06 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. if (-e "/var/netscape/fasttrack/bin/admin/ns-admin") { $nss = 2; }
  26. elsif (-e "/var/netscape/suitespot/bin/admin/ns-admin") { $nss = 1; } 
  27. else { $nss = 0; }
  28.  
  29. if ($nss == 2) {
  30.     $serv_root    = "/var/netscape/fasttrack";
  31.     $pid_file    = $serv_root . "/admin-serv/logs/pid";
  32.     $conf_file    = $serv_root . "/admin-serv/config/ns-admin.conf";
  33.     $pw_file    = $serv_root . "/admin-serv/config/admpw";
  34.     $def_acl     = $serv_root . "/adminacl/admin-defaults.acl";
  35. } elsif ($nss == 1) {
  36.     $serv_root = "/var/netscape/suitespot";
  37.     
  38.     $pid_file       = $serv_root . "/admin-serv/logs/pid";
  39.     $conf_file      = $serv_root . "/admin-serv/config/ns-admin.conf";
  40.     $pw_file        = $serv_root . "/admin-serv/config/admpw";
  41.     $def_acl        = $serv_root . "/adminacl/admin-defaults.acl";
  42.  
  43. } else {
  44.     $serv_root = "/usr/ns-home";
  45.  
  46.     $pid_file       = $serv_root . "/admserv/pid";
  47.     $conf_file      = $serv_root . "/admserv/ns-admin.conf";
  48.     $pw_file        = $serv_root . "/admserv/admpw";
  49. }
  50. $start_ns_admin     = $serv_root . "/start-admin > /dev/null 2>&1";
  51. $stop_ns_admin      = $serv_root . "/stop-admin > /dev/null 2>&1";
  52. $dummy              = $conf_file . ".tmp";
  53.  
  54. $title = "Netscape Admin Server Access Control";
  55. $myname = "security.cgi";
  56. $help_page = "security-help.html";
  57.  
  58. $js_generic = 
  59. "which = \"none\";
  60. function runSubmit() {
  61.     if(which == \"add\") return runAdd();
  62.     if(which == \"edit\") return runEdit();
  63.     if(which == \"delete\") return runDelete();
  64.     return runDo();
  65. }
  66. function markAdd() { which = \"add\"; }
  67. function markEdit() { which = \"edit\"; }
  68. function markDelete() { which = \"delete\"; }
  69. function markOther() { which = \"none\"; }
  70. $js_error_box
  71. $js_help
  72. $js_meta
  73. $js_ip
  74. $js_hostname
  75. function runEdit()  {
  76.     Ctrl = document.AccountForm.chosen
  77.     none = true;
  78.     for(j = 0; j < Ctrl.length; j++) {
  79.         if (Ctrl.options[j].selected) { none = false; break; }
  80.     }
  81.     if (none) {
  82.         errorBox (Ctrl, \"To edit an existing account, \"
  83.             + \"first select an account\\nfrom the list, \"
  84.             + \"then click the edit button.\");
  85.         return (false);
  86.     }
  87.     return (true);
  88. }
  89. function runDelete() {
  90.     Ctrl = document.AccountForm.chosen;
  91.     none = true;
  92.     for(j = 0; j < Ctrl.length; j++) {
  93.         if (Ctrl.options[j].selected) { none = false; break; }
  94.     }
  95.     if (none) {
  96.         errorBox (Ctrl, \"To delete an existing account, first \"            
  97.             + \"select an account\\nfrom the list, then click \"
  98.             + \"the delete button.\");
  99.         return (false);
  100.     }
  101.     return (true);
  102. }
  103. function runDo() {
  104.     if (!testStarList(document.AccountForm.clients)) return (false);
  105.     return (true);
  106. }
  107. function is_ip(word) {
  108.     ipChars = \"0123456789\.*\";
  109.     for (ii=0; ii<word.length; ii++) {
  110.         c = word.charAt(ii);
  111.                if (ipChars.indexOf(c, 0) == -1) {
  112.             return (false);
  113.         }
  114.     }
  115.     return (true);
  116. }
  117. function remove_star(word) {
  118.     if (word.indexOf(\"*\", 0) == -1) return (word);
  119.     new_word = \"\";
  120.     for (jj = 0; jj < word.length; jj++) {
  121.         if (word.charAt(jj) == \"*\") 
  122.             new_word = new_word + \"233\";
  123.         else 
  124.             new_word = new_word + word.charAt(jj);
  125.     }
  126.     return (new_word);
  127. }            
  128. function testStarList(Ctrl) {
  129.     my_count = 0;
  130.     ipChars = \"0123456789\.*\";
  131.     whitespace = \" \\n\\r\\t\\f\";  space = true;
  132.     for(start=0, cur=0; cur < Ctrl.value.length; cur++) {
  133.         for(i = 0; i < whitespace.length; i++) {
  134.             c = whitespace.charAt(i);
  135.             if (Ctrl.value.charAt(cur) == c) { // found whitespace
  136.                 if (space == false) { 
  137.                     space = true;  
  138.                     if(cur != start) { 
  139.                         host = Ctrl.value.substring(start,cur); 
  140.                         my_count++; 
  141.                         if (is_ip(host)) {
  142.                             new_host = remove_star(host);
  143.                             if (!testIPaddress(new_host,false)) { 
  144.                                 errorBox (Ctrl, \"Invalid server IP address: \" + host + \"\\nin server address list.\"); 
  145.                                 return (false);                             }
  146.                         } else {
  147.                             if (!testHostname(Ctrl, host, \"hostname\", false)) return (false);
  148.                         } 
  149.                     } 
  150.                 }
  151.                 break;
  152.             } else {               // found character
  153.                 if (space == true) { space = false; start = cur; }
  154.             }
  155.         }
  156.     }
  157.     if(cur != start && space == false) { 
  158.         host = Ctrl.value.substring(start,cur); 
  159.         my_count++; 
  160.         if (is_ip(host)) {
  161.             new_host = remove_star(host);
  162.             if (!testIPaddress(new_host,false)) { 
  163.                 errorBox (Ctrl, \"Invalid server IP address: \" + host + \"\\nin server address list.\"); 
  164.                 return (false); 
  165.             } 
  166.         } else {
  167.             if (!testHostname(Ctrl, host, \"hostname\", false)) return (false);
  168.         }
  169.     }
  170.     return (true);
  171. }
  172. function runAdd() {
  173.     Ctrl = document.AccountForm.new_account;
  174.     if (Ctrl.value.length == 0) {
  175.         errorBox(Ctrl, \"To add a new account, first enter \\n\"
  176.             +\"the new account name.\");
  177.         return (false);
  178.     }
  179.     if (!testMeta(Ctrl, \"account name\")) return (false);  
  180.     return (true);
  181. }";
  182.  
  183. $js_edit = 
  184. "$js_standard
  185. $js_error_box
  186. $js_help
  187. $js_meta
  188. function checkForm(form)  {
  189.     if (form.uname.value.length == 0) {
  190.         errorBox(form.uname, \"Account name cannot be empty.\");
  191.         return (false);
  192.     }
  193.     if (!testMeta(form.uname, \"account name\")) return (false);
  194.     return (true);
  195. }";
  196.  
  197. print "Content-type: text/html\n\n";
  198.  
  199. &get_fields;
  200. &get_accounts;
  201.  
  202. if (%fld) {
  203.     $fld{'chosen'} =~ /([\w.-]+)/; $chosen = $1;
  204.  
  205.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  206.     $help =~ s/cgi$/hlp/;
  207.     exec $help if ($fld{'help'} eq "Help");
  208.  
  209.     if ($fld{'edit'}) {
  210.         &get_edit($chosen);
  211.     } elsif ($fld{'do_edit'}) {
  212.         &generic;
  213.     } elsif ($fld{'add'}) {
  214.         &get_add;
  215.     } elsif ($fld{'delete'}) {
  216.         &generic($chosen);    
  217.     } elsif ($fld{'doit'}) {
  218.         $fld{'adm_pwd'} =~ s/\s//g;
  219.         if (($nss != 0) && ($fld{'adm_pwd'} ne $fld{'adm_pwd2'})) {
  220.             $js_badpw = "
  221.             function bad_password() {
  222.                 Ctrl = document.AccountForm.adm_pwd;
  223.                 errorBox(Ctrl, \"The two passwords are not identical.\");
  224.                 return(true);
  225.             }";
  226.             $js_generic .= $js_badpw;
  227.         } else {
  228.             &do_it;
  229.             &get_accounts;
  230.         }
  231.         &generic;
  232.     } elsif ($fld{'doedit'}) {
  233.         $fld{'password'} =~ s/\s//g;
  234.         if (! $fld{'password'}) {
  235.             $js_badpw = "
  236.             function bad_password() {
  237.                 Ctrl = document.StandardForm.password;
  238.                 errorBox(Ctrl, \"A password is required.\");
  239.                 return(true);
  240.             }";
  241.             $js_edit .= $js_badpw;
  242.             $fld{'edit'} = "Resetting this." if ($fld{'old_account'});
  243.             &get_edit($fld{'uname'});
  244.         } elsif ($fld{'password'} ne $fld{'password2'}) {
  245.             $js_badpw = "
  246.             function bad_password() {
  247.                 Ctrl = document.StandardForm.password;
  248.                 errorBox(Ctrl, \"The two passwords are not identical.\");
  249.                 return(true);
  250.             }";
  251.             $js_edit .= $js_badpw;
  252.             $fld{'edit'} = "Resetting this." if ($fld{'old_account'});
  253.             &get_edit($fld{'uname'});
  254.         } else {
  255.             &do_edit;
  256.             &get_accounts;
  257.             &generic;
  258.         }
  259.     }
  260. } else { &generic; }
  261.  
  262. sub do_it {
  263.     if ($nss > 0 && $fld{'adm_pwd'}) { &new_super; }
  264.     else { &do_delete($fld{'deleted'}) if $fld{'deleted'}; }
  265.     &process_clients;
  266.     &bounce_server;
  267. }
  268.  
  269. sub process_clients {
  270.     @clients = split(/\s+/, $fld{'clients'});
  271.     foreach (@clients) {
  272.         if ($_ =~ /[^0-9\.\*]/) { push(@hosts, $_); }
  273.         else { push(@adds, $_); }
  274.     }
  275.     if ($#hosts > 0) { $hosts = "(" . join('|', @hosts) . ")"; }
  276.     elsif ($#hosts == 0) { $hosts = $hosts[0]; }
  277.     else { $hosts = ""; }
  278.  
  279.     if ($#adds > 0) { $adds = "(" . join('|', @adds) . ")"; }
  280.     elsif ($#adds == 0) { $adds = $adds[0]; }
  281.     else { $adds = ""; }
  282.  
  283.     $hosts_added = 0;
  284.     $adds_added = 0;
  285.     open(IN, "< $conf_file");
  286.     open(OUT, "> $dummy");
  287.     while(<IN>) {
  288.         if ($_ =~ /^Hosts\s/) {
  289.             $hosts_added = 1;
  290.             if ($hosts ne "") { print OUT "Hosts $hosts\n"; }
  291.         } elsif ($_ =~ /^Addresses\s/) {
  292.             $adds_added = 1;
  293.             if ($adds ne "") { print OUT "Addresses $adds\n"; }
  294.         } else { print OUT $_; }
  295.     }
  296.     if ($hosts ne "" && $hosts_added == 0) {
  297.         print OUT "Hosts $hosts\n"; 
  298.     }
  299.     if ($adds ne "" && $adds_added == 0) {
  300.         print OUT "Addresses $adds\n";
  301.     }
  302.  
  303.     close(IN);
  304.     close(OUT);
  305.  
  306.     rename($dummy, $conf_file);
  307.  
  308.     $message .= "  Client list updated.";
  309. }
  310.  
  311. sub bounce_server {
  312.     open(IN, "< $pid_file");
  313.     $pid = <IN>;
  314.     close(IN);
  315.     if ($pid) {
  316.         system($stop_ns_admin);
  317.         if ($nss > 0) { sleep(5); }
  318.         system($start_ns_admin);
  319.     }
  320. }
  321.  
  322. sub new_super {
  323.     if ($fld{'adm_pwd'}) {
  324.         $salt = &mksalt;
  325.         $pswd = crypt($fld{'adm_pwd'}, $salt);
  326.         $line = $fld{'adm_name'} . ":" . $pswd;
  327.  
  328.         open(OUT, "> $pw_file");
  329.         print OUT $line;
  330.         close(OUT);
  331.  
  332.         open(IN, "< $def_acl");
  333.         open(OUT, "> $dummy");
  334.         while(<IN>) {
  335.             if ($_ =~ /^allow absolute/) {
  336.                 $_ =~ s/\".*\"/\"$fld{'adm_name'}\"/;
  337.             }
  338.             print OUT $_;
  339.         }
  340.         close(IN);
  341.         close(OUT);
  342.         rename($dummy, $def_acl);
  343.         
  344.         $message .= "Super-user updated.<br>";
  345.     }
  346. }
  347.  
  348. sub do_delete {
  349.     open(IN, "< $pw_file");
  350.     open(OUT, "> $dummy");
  351.     while(<IN>) {
  352.         print OUT $_ unless $_[0] eq (split(/:/, $_))[0];
  353.     }
  354.     close(IN);
  355.     close(OUT);
  356.     
  357.     rename($dummy, $pw_file);
  358.     &bounce_server;
  359.  
  360.     $message .= "Account deleted.";
  361. }
  362.  
  363. sub do_edit {
  364.     $salt = &mksalt;
  365.     $pswd = crypt($fld{'password'}, $salt);
  366.     $line = $fld{'uname'} . ":" . $pswd;
  367.  
  368.     if ($fld{'old_account'} ne "") {
  369.         open(IN, "< $pw_file");
  370.         open(OUT, "> $dummy");
  371.         while(<IN>) {
  372.             if ($fld{'old_account'} eq (split(/:/, $_))[0]) {
  373.                 print OUT "$line\n";
  374.             } else { print OUT $_; }
  375.         }
  376.         close(IN);
  377.         close(OUT);
  378.  
  379.         rename($dummy, $pw_file);
  380.  
  381.         $message .= "Account edited.";
  382.     } else { 
  383.         open(OUT, ">> $pw_file");
  384.         print OUT "$line\n";
  385.         close(OUT);
  386.  
  387.         $message .= "Account added.";
  388.     }
  389.     
  390.     &bounce_server;
  391. }
  392.  
  393. sub get_add {
  394.     &get_edit($fld{'new_account'});
  395. }
  396.  
  397. sub get_edit {
  398.     if (! $js_badpw) {
  399.         $js_badpw = $js_empty_passwd_check; 
  400.         $js_edit .= $js_badpw;
  401.     }
  402.     &js_title_block($title, $js_edit);
  403.     if ($fld{'add'}) { &header_block("Add Account"); }
  404.     else { &header_block("Edit Account"); }
  405.     print "<body onLoad='bad_password()'>\n";
  406.     print "<form name=StandardForm action=$myname method=post "
  407.         . "onSubmit=\"return runSubmit()\">\n"
  408.         . "<i>$message</i>\n"
  409.         . "<center><br><table width=400>\n";
  410.  
  411.     if ($fld{'edit'}) {
  412.         print "<input type=hidden name='old_account' value=$_[0]>\n";
  413.     }
  414.  
  415.     print "<tr><th align=left>Account name:<td>"
  416.         . &text("uname", $_[0], 20)
  417.         . "</td></tr>\n";
  418.  
  419.     print "<tr><th align=left>Account password:<td>"
  420.         . "<input type=password name=\"password\" size=20>"
  421.         . "</td></tr>\n";
  422.  
  423.     print "<tr><th align=left>Retype password:<td>"
  424.         . "<input type=password name=\"password2\" size=20>"
  425.         . "</td></tr>\n";
  426.  
  427.     print "</table></center><br>\n";
  428.  
  429.     print &js_buttons('doedit','Ok','onClick="markOK()"',
  430.                 'onClick="markOther()"',
  431.                 "onClick=\"do_help('$help_page'); return (false)\"");
  432.     print "</body>\n";
  433. }
  434.     
  435. sub get_accounts {
  436.     if ($nss > 0) {
  437.         open(IN, "< $pw_file");
  438.         $val{'adm_name'} = (split(/:/, <IN>))[0];
  439.         close(IN);
  440.     } else {
  441.         undef @accounts;
  442.         open(IN, "< $pw_file");
  443.         while(<IN>) {
  444.             push(@accounts, (split(/:/, $_))[0]);
  445.         }
  446.         close(IN);
  447.     }
  448.  
  449.     undef @clients;
  450.     open(IN, "< $conf_file");
  451.     while(<IN>) {
  452.         if ($_ =~ /^Hosts\s+(.*)/) {
  453.             $list = $1;
  454.             if ($list =~ /\((.*)\)/) {
  455.                 push(@clients, split(/\|/, $1));
  456.             } else {
  457.                 push(@clients, $list);
  458.             }
  459.         } elsif ($_ =~ /^Addresses\s+(.*)/) {
  460.             $list = $1;
  461.             if ($list =~ /\((.*)\)/) {
  462.                 push(@clients, split(/\|/, $1));
  463.             } else {
  464.                 push(@clients, $list);
  465.             }
  466.         }
  467.     }
  468.     close(IN);
  469.     $val{'clients'} = join("\n", @clients);
  470. }
  471.  
  472. sub generic {
  473.     if (! $js_badpw) {
  474.         $js_badpw = $js_empty_passwd_check; 
  475.         $js_generic .= $js_badpw;
  476.     }
  477.     &js_title_block($title, $js_generic);
  478.     &header_block($title);
  479.     
  480.     print "<body onLoad='bad_password()'>\n";
  481.     if ($_[0]) { $message .=  qq|Click "Ok" to save changes.|; }
  482.  
  483.     print "<form name=AccountForm action=$myname method=post "
  484.         . "onSubmit=\"return runSubmit()\">\n";
  485.  
  486.     print "<input type=hidden name=nss value=$nss>\n";
  487.  
  488.     print "<i>$message</i>\n";
  489.  
  490.     if ($nss > 0) {
  491.         print "<br>\n"
  492.         . "<h3>Super user:</h3><center><table width=400>\n"
  493.         . "<tr><th align=left>Name:<td><input name=\"adm_name\" value=\"$val{'adm_name'}\" size=19></td></tr>\n"
  494.         . "<tr><th align=left>Password:<td><input type=password name=\"adm_pwd\" size=19></td></tr>\n"
  495.         . "<tr><th align=left>Retype password:<td><input type=password name=\"adm_pwd2\" size=19></td></tr>\n";
  496.  
  497.         print "</table></center><br>";
  498.     } else {
  499.         print "<br>\n"
  500.         . "<h3>Allowed users:</h3><center><table width=400>\n"
  501.         . "<tr><td><input type=submit name=\"add\" onClick=\"markAdd()\" \n"
  502.         . "value=\"Add New Account\"\n"
  503.         . "</td><td><input name=\"new_account\" value=\"$val{'new_account'}\"\n" 
  504.         . "size=19 onClick=\"markAdd()\"></td></tr>\n";
  505.         
  506.         if ($#accounts >= 0) {
  507.         if ($_[0]) {
  508.             undef @show_accts;
  509.             foreach $arg (@accounts) {
  510.                 push(@show_accts, $arg) if $arg ne $_[0];
  511.             }
  512.             print "<input type=hidden name=deleted value=$_[0]>\n";
  513.         } else { @show_accts = @accounts; }
  514.  
  515.         print "<tr><td>\n"
  516.             . "<input type=submit name=\"edit\" onClick=\"markEdit()\" \n"
  517.             . "value=\"Edit Selected Account\"></td><td rowspan=2>";
  518.         print &choice_list(*show_accts, "chosen", 20);
  519.         print "</td/tr>\n"
  520.             . "<tr><td><input type=submit name=\"delete\" onClick=\"markDelete()\" \n"
  521.             . "value=\"Delete Selected Account\"></td></tr>\n";
  522.         }
  523.  
  524.         print "</table></center><br>";
  525.     }
  526.  
  527.     print "<h3>Allowed clients:</h3>\n"
  528.         . "<center>\n"
  529.         . "<textarea name='clients' cols=20 rows=4>"
  530.         . $val{'clients'}
  531.         . "</textarea><br><br>\n";
  532.  
  533.     print &js_buttons('doit','Ok','onClick="markOther()"',
  534.                 'onClick="markOther()"',
  535.                 "onClick=\"do_help('$help_page'); return (false)\"");
  536.     print "</body>\n";
  537. }
  538.